package com.promote.hotspot.server.launcher;

import com.promote.hotspot.server.netty.client.IClientEventListener;
import com.promote.hotspot.server.netty.filter.INettyMsgFilter;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

import com.promote.hotspot.server.netty.NodeServer;

/**
 * @author enping.jep
 * @date 2023/11/15 15:03
 **/
@Slf4j
@Component
public class NodesServerLauncher {

    @Value("${netty.port}")
    private int port;

    @Resource
    private IClientEventListener clientEventListener;
    @Resource
    private List<INettyMsgFilter> messageFilters;

    @PostConstruct
    public void start() {
        log.info("netty server is starting");
        NodeServer nodeServer = new NodeServer();
        nodeServer.setClientEventListener(clientEventListener);
        nodeServer.setMessageFilters(messageFilters);
        try {
            nodeServer.startNettyServer(port);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
